print('coder')

from graph import graph, thread
# graph.get_graph().print_ascii()

# config = {"configurable": {"thread_id": "1"}}

def do_stream(user_input):
    for value in graph.stream(
        {"messages": [("user", user_input)]}, thread, stream_mode="values"
    ):

        value["messages"][-1].pretty_print()
        print("AI:", value["messages"][-1].content)

while True:
    user_input = input("User: ")
    if user_input.lower() in ["quit", "exit", "q"]:
        print("Goodbye!")
        break

    do_stream(user_input)
    
    try:
        user_approval = input("Do you want to call tool? (yes/no): ")
    except:
        user_approval = "yes"

    if user_approval.lower() == "yes":
        # If approved, continue the graph execution
        for event in graph.stream(None, thread, stream_mode="updates"):
            print(event)
            value = next(iter(event.values()))
            print("AI:", value["messages"][-1].content)
    else:
        print("Operation cancelled by user.")
